package com.fucking.great.context;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.fucking.great.context.config.SystemConfigBean;
import com.fucking.great.context.config.TxnConfiger;
import com.fucking.great.context.handler.GreatHandler;
import com.fucking.great.context.handler.HandlerTemplate;
import com.fucking.great.context.handler.SemaphoreHandlerDecorator;
import com.fucking.great.context.plun.Plug;
import com.fucking.great.context.plun.PlugFactory;
import com.fucking.great.context.util.SingleUtil;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class GreatMain {
    public static final Log log = LogFactory.get();
    private static GreatHandler SINGLE = new SemaphoreHandlerDecorator(new HandlerTemplate(){});

    public final static GreatHandler getSingle() {
        return SINGLE;
    }

    public final static synchronized void setSingle(GreatHandler Single) {
        log.warn("run set HadnlerTemplate SINGLE  , please HadnlerTemplate is ok . new HadnlerTemplate is [{}]",SINGLE);
        // 先销毁
        GreatHandler old = SINGLE;
        old.destroy();
        // 替换
        SINGLE = Single;
    }

    public final static  Object doService(TxnContext text) {
       return  getSingle().doService(text);
    }

}
